
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package actions;

//~--- non-JDK imports --------------------------------------------------------
import SessionFactory.SessionFactoryUtil;
import beans.DisplayTopicActionFormBean;
import client.TopicsPosts;
import dto.Sections;
import dto.Topics;
import dto.TopicsHome;

import java.math.BigInteger;


import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

//~--- JDK imports ------------------------------------------------------------

import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Deena
 */
public class DisplayTopicAction extends org.apache.struts.action.Action {

    private static final String SUCCESS = "success";
    TopicsHome topicHome = new TopicsHome();
    Vector<Topics> topics = new Vector<Topics>();
    Vector<Sections> sec;
    TopicsPosts postsModel;

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response)
            throws Exception {

        postsModel = new TopicsPosts();
        ActionForward forward = new ActionForward();
        Sections section = new Sections();
        String secID = request.getParameter("section");
        Integer secId;
        ////// hasnaa logout
        /*if(request.getSession().getAttribute("userBean")!= null)
        {

        }*/
        if (secID != null) {
            secId = new Integer(secID);
        }
        else{
            secId = new Integer(1);
        }
        section.setSectionid(secId);
        postsModel.getInsideSection(section);
        sec = postsModel.getInnerSections();
        topics = postsModel.getInnerTopics();
        if (sec.size() != 0 || topics.size() != 0) {
            ((DisplayTopicActionFormBean) form).setNumber(new int[0]);
            ((DisplayTopicActionFormBean) form).setSectionId(secId);
            ((DisplayTopicActionFormBean) form).setSec(sec);
            ((DisplayTopicActionFormBean) form).setTopics(topics);
        }
        //request.setAttribute("sectionid", secID);
        ///////////////////////////////////////// Amr Ig /////////////////////////////////////
        String home=request.getParameter("home");
         request.setAttribute("parentTree", null);        
         request.setAttribute("parent", null);
        if(home==null && secID!=null){
             Vector<Sections> parents=null;
         Sections sect = postsModel.getSection(Integer.parseInt(secID));       
         parents =postsModel.getParentTree(sect);
         request.setAttribute("parentTree", parents);         
         request.setAttribute("parent", sect);
        }
       
        return mapping.findForward("done");
    }
}
//~ Formatted by Jindent --- http://www.jindent.com

